﻿using System.Collections.Generic;
using System.Linq;
using LINQtoFxCop.Core;
using Microsoft.FxCop.Sdk;

namespace LINQtoFxCop.Flaws.Implementation
{
  internal sealed class ImplementationDoNotDependDirectlyOnCertainStaticObjects : FlawsIntrospectionRule
  {
    private readonly HashSet<string> _staticReferences;

    public ImplementationDoNotDependDirectlyOnCertainStaticObjects()
      : base("ImplementationDoNotDependDirectlyOnCertainStaticObjects")
    {
      _staticReferences = new HashSet<string>()
                            {
                              "System.Web.HttpContext.get_Current",
                              "AnalysisTarget.Flaws.Implementation.ClassWithStaticInstanceObject.get_Instance" 
                            };

    }


    protected override IEnumerable<QueryResult> Query()
    {
      return
        from method in Methods
        where method.Instructions.HasItemWhen(instruction => instruction.OpCode == OpCode.Call && _staticReferences.Contains(instruction.Value.ToString()))
        select Result(method);
    }
  }
}
